home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 943 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  3.1 KB

  1. Path: news.microsoft.com!news
  2. From: warlok@siu.edu (Jon Fincher)
  3. Newsgroups: comp.lang.c,comp.lang.c++
  4. Subject: Re: Q: Time to call a function?
  5. Date: 8 Jan 1996 15:00:48 GMT
  6. Organization: Microsoft Corp.
  7. Message-ID: <4crbj0$9v6@news.microsoft.com>
  8. References: <4cnjsf$kq0@mark.ucdavis.edu> <30F0E881.5F3D@vcx.net>
  9. NNTP-Posting-Host: 157.54.53.180
  10. Mime-Version: 1.0
  11. Content-Type: Text/Plain; charset=US-ASCII
  12. X-Newsreader: WinVN 0.99.7
  13.  
  14. In article <30F0E881.5F3D@vcx.net>, barnold@vcx.net says...
  15. >
  16. >> About how much time does calling a function, allocating memory, and
  17. >> executing simple statements like "i = 3" take? 
  18. >
  19. >The Intel programmers reference manual lists the number of clocks for 
  20. >each instruction.  This varies from about 2 to 250.  The above 
  21. >assignment statement probably uses a memory MOV which may take 20 clocks
  22. >depending on the processor.  A 'CALL' to a subroutine can take over 200.
  23. >Memory allocation might require many CALL's and other instructions
  24. >amounting to perhaps 10,000 to 100,000 clocks.
  25. >
  26. >To get back to 'time' (for the ballpark calculation) note that a 
  27. >processor running at 66 MHZ has a clock time of 15 nanoseconds.
  28. >( 1 / 66,000,000 ).  That memory allocation which required 100,000
  29. >clocks will take 1.5 milliseconds.  That assignment will take 
  30. >20 * 15ns = 300ns or 0.3 microsecs.  
  31. >
  32. >It can be very tedious to try to calculate the exact value by looking
  33. >at the assembly source code; that's what benchmarks are for.
  34. >Note also that in real computers, most of the time is spent doing data
  35. >input / output to storage devices and sending data to the screen.
  36.  
  37. Bruce:
  38.  
  39. You also might want to mention pipelining, which speeds up a lot of 
  40. processors.
  41.  
  42. Pipelining is the ability of a microprocessor to work on more than one 
  43. instruction at a time.  For example, there are a few basic steps to executing 
  44. an assembly instruction :
  45.  
  46. 1) Fetch the instruction.  This entails reading the assembly code from memory 
  47. and placing it in a processor register.
  48.  
  49. 2) Decode the instruction.  This is a proces by which the processor figures 
  50. out what the instruction means.
  51.  
  52. 3) Fetch the data.  Any data the instruction needs is in memory following the 
  53. actual instruction.  This is where the data is retrieved.
  54.  
  55. 4) Execute the instruction.  This is an obvious step.
  56.  
  57. A microprocessor can speed operations up by pipelining instructions, i.e. 
  58. having a different instruction in each step.  For example, in our model above, 
  59. we could be executing Inst. A, fetching the dat for Inst. B, Decoding Inst. C, 
  60. and fetching Inst. D, so the processor is working on four instructions at 
  61. once.  Each instruction may take multiple clock cycles, ut now the clock 
  62. cycles required for one instruction overlap the clock cycles required for 
  63. neighbor instructions, reducing the overall clock cycle requirements and 
  64. speeding the program up.
  65.  
  66. Most compilers are designed to take advantage of pipelining by keeping low 
  67. clock cycle instructions together and not using (if possible) large clock 
  68. cycle instructions.  Large clock cycle instructions back pipelines up.
  69.  
  70. Any other comments?  Did I miss anything?
  71.  
  72. Jon
  73.  
  74.